package com.demo.business.datingext;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 
 * @create: 2022-02-25 23:30:03
 **/
@Service("datingext")
@Slf4j
public class DatingextService{

    @Resource
    DatingextDao datingextDao;

    /**
     * 添加,获取lDatingExtId数据
     *
     * @param cdoRequest - lDatingExtId:id
     *                   - lDatingId:id
     *                   - sContent:内容
     *                   - nType:消息类型：0，预约，1、消费，
     *                   - lJoinerId:参与人id
     *                   - lInitiatorId:发起人id
     *                   - nStatus:消息类型：0，正常，1、申请通过，2、申请拒绝
     *                   - dCreateTime:创建时间
     *                   - dUpdateTime:更新时间
     * @return
     * @author 
     * @create: 2022-02-25 23:30:03
     */
    @OpenApi
    public Return addDatingext(CDO cdoRequest) {
        datingextDao.addDatingext(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("lDatingExtId")) {
            cdoResult.set("lDatingExtId", cdoRequest.get("lDatingExtId"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据lDatingExtId，更新数据
     *
     * @param cdoRequest - lDatingExtId:id
     *                   - lDatingId:id
     *                   - sContent:内容
     *                   - nType:消息类型：0，预约，1、消费，
     *                   - lJoinerId:参与人id
     *                   - lInitiatorId:发起人id
     *                   - nStatus:消息类型：0，正常，1、申请通过，2、申请拒绝
     *                   - dCreateTime:创建时间
     *                   - dUpdateTime:更新时间
     * @return
     * @author 
     * @create: 2022-02-25 23:30:03
     */
    @OpenApi
    public Return updateDatingextById(CDO cdoRequest) {
        int affectedRows = datingextDao.updateDatingextById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据lDatingExtId，删除数据
     *
     * @param cdoRequest - lDatingExtId:id
     * @return
     * @author 
     * @create: 2022-02-25 23:30:03
     */
    //@OpenApi
    public Return deleteDatingextById(CDO cdoRequest){
        int affectedRows = datingextDao.deleteDatingextById(cdoRequest.getLong("lDatingExtId"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除数据
     *
     * @param cdoRequest - lDatingId:id
     *                   - nType:消息类型：0，预约，1、消费，
     *                   - lJoinerId:参与人id
     *                   - dCreateTime:创建时间
     * @return
     * @author 
     * @create: 2022-02-25 23:30:03
     */
    //@OpenApi
    public Return deleteDatingext(CDO cdoRequest) {
        int affectedRows = datingextDao.deleteDatingext(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取数据
     *
     * @param cdoRequest - lDatingExtId:id
     * @return
     * @author 
     * @create: 2022-02-25 23:30:03
     */
    @OpenApi
    public Return getDatingextById(CDO cdoRequest) {
        CDO cdoMapperResult = datingextDao.getDatingextById(cdoRequest.getLong("lDatingExtId"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取数据
     *
     * @param cdoRequest - lDatingExtId:id
     *                   - lDatingId:id
     *                   - nType:消息类型：0，预约，1、消费，
     *                   - lJoinerId:参与人id
     *                   - dCreateTime:创建时间
     * @return
     * @author 
     * @create: 2022-02-25 23:30:03
     */
    @OpenApi
    public Return getDatingext(CDO cdoRequest) {
        CDO cdoMapperResult = datingextDao.getDatingext(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取数据列表
     *
     * @param cdoRequest - lDatingId:id
     *                   - nType:消息类型：0，预约，1、消费，
     *                   - lJoinerId:参与人id
     *                   - dCreateTime:创建时间
     * @return
     * @author 
     * @create: 2022-02-25 23:30:03
     */
    @OpenApi
    public Return getDatingextList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = datingextDao.getDatingextList(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = datingextDao.getDatingextListCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取数据列表
     *
     * @param cdoRequest - lDatingExtId:id
     *                   - lDatingId:id
     *                   - nType:消息类型：0，预约，1、消费，
     *                   - lJoinerId:参与人id
     *                   - dCreateTime:创建时间
     * @return
     * @author 
     * @create: 2022-02-25 23:30:03
     */
    @OpenApi
    public Return getDatingextListByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = datingextDao.getDatingextListByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = datingextDao.getDatingextListByConditionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
